/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.sentence;

import view.controller.sentence.ControllerSentence;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UnsupportedLookAndFeelException;
import model.corpus.Corpus;

/**
 *
 * @author Djordje Gligorijevic
 */
public class FrmAddTaggedSentence extends javax.swing.JDialog {

    private ControllerSentence controllerSentence;

    /**
     * Creates new form FrmAddTaggedSentence
     */
    public FrmAddTaggedSentence(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAreaSentence = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAreaTags = new javax.swing.JTextArea();
        btnAddTaggedSentence = new javax.swing.JToggleButton();
        cmbBoxCorpus = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Type sentence in text area below (separate words(tokens) with space): ");

        txtAreaSentence.setColumns(20);
        txtAreaSentence.setRows(5);
        jScrollPane1.setViewportView(txtAreaSentence);

        jLabel2.setText("Type tags in same order as words in sentence in text area below (also semaprate tags with space): ");

        txtAreaTags.setColumns(20);
        txtAreaTags.setRows(5);
        jScrollPane2.setViewportView(txtAreaTags);

        btnAddTaggedSentence.setText("Add tagged sentence");
        btnAddTaggedSentence.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddTaggedSentenceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(cmbBoxCorpus, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnAddTaggedSentence)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddTaggedSentence)
                    .addComponent(cmbBoxCorpus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddTaggedSentenceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddTaggedSentenceActionPerformed
        try {
            String sentence = getTxtAreaSentence().getText().trim();
            String tags = getTxtAreaTags().getText().trim();

            getControllerSentence().addTaggedSentence(sentence, tags, (Corpus) getCmbBoxCorpus().getSelectedItem());
            getControllerSentence().refreshStorageData();
            JOptionPane.showMessageDialog(this, "Entered tagged sentence has been successfully saved.");
            getTxtAreaSentence().setText("");
            getTxtAreaTags().setText("");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "There was an error trying to save new TaggedSentence object."+ex.getMessage());
            getTxtAreaSentence().setText("");
            getTxtAreaTags().setText("");
        }
    }//GEN-LAST:event_btnAddTaggedSentenceActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                try {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(FrmAddTaggedSentence.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(FrmAddTaggedSentence.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(FrmAddTaggedSentence.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(FrmAddTaggedSentence.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;
            }
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                FrmAddTaggedSentence dialog = new FrmAddTaggedSentence(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton btnAddTaggedSentence;
    private javax.swing.JComboBox cmbBoxCorpus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea txtAreaSentence;
    private javax.swing.JTextArea txtAreaTags;
    // End of variables declaration//GEN-END:variables

//    private void fillComboBoxKorpus(){
//        for (int i = 0; i < storage.KorpusPersistence.getInstance().getKorpus().size(); i++) {
//            cmbBoxCorpus.addItem(storage.KorpusPersistence.getInstance().getKorpus().get(i));
//        }
//    }
    /**
     * @return the controllerSentence
     */
    public ControllerSentence getControllerSentence() {
        return controllerSentence;
    }

    /**
     * @param controllerSentence the controllerSentence to set
     */
    public void setControllerSentence(ControllerSentence controllerSentence) {
        this.controllerSentence = controllerSentence;
    }

    /**
     * @return the btnAddTaggedSentence
     */
    public javax.swing.JToggleButton getBtnAddTaggedSentence() {
        return btnAddTaggedSentence;
    }

    /**
     * @param btnAddTaggedSentence the btnAddTaggedSentence to set
     */
    public void setBtnAddTaggedSentence(javax.swing.JToggleButton btnAddTaggedSentence) {
        this.btnAddTaggedSentence = btnAddTaggedSentence;
    }

    /**
     * @return the cmbBoxCorpus
     */
    public javax.swing.JComboBox getCmbBoxCorpus() {
        return cmbBoxCorpus;
    }

    /**
     * @param cmbBoxCorpus the cmbBoxCorpus to set
     */
    public void setCmbBoxCorpus(javax.swing.JComboBox cmbBoxCorpus) {
        this.cmbBoxCorpus = cmbBoxCorpus;
    }

    /**
     * @return the jLabel1
     */
    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    /**
     * @param jLabel1 the jLabel1 to set
     */
    public void setjLabel1(javax.swing.JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    /**
     * @return the jLabel2
     */
    public javax.swing.JLabel getjLabel2() {
        return jLabel2;
    }

    /**
     * @param jLabel2 the jLabel2 to set
     */
    public void setjLabel2(javax.swing.JLabel jLabel2) {
        this.jLabel2 = jLabel2;
    }

    /**
     * @return the jScrollPane1
     */
    public javax.swing.JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    /**
     * @param jScrollPane1 the jScrollPane1 to set
     */
    public void setjScrollPane1(javax.swing.JScrollPane jScrollPane1) {
        this.jScrollPane1 = jScrollPane1;
    }

    /**
     * @return the jScrollPane2
     */
    public javax.swing.JScrollPane getjScrollPane2() {
        return jScrollPane2;
    }

    /**
     * @param jScrollPane2 the jScrollPane2 to set
     */
    public void setjScrollPane2(javax.swing.JScrollPane jScrollPane2) {
        this.jScrollPane2 = jScrollPane2;
    }

    /**
     * @return the txtAreaSentence
     */
    public javax.swing.JTextArea getTxtAreaSentence() {
        return txtAreaSentence;
    }

    /**
     * @param txtAreaSentence the txtAreaSentence to set
     */
    public void setTxtAreaSentence(javax.swing.JTextArea txtAreaSentence) {
        this.txtAreaSentence = txtAreaSentence;
    }

    /**
     * @return the txtAreaTags
     */
    public javax.swing.JTextArea getTxtAreaTags() {
        return txtAreaTags;
    }

    /**
     * @param txtAreaTags the txtAreaTags to set
     */
    public void setTxtAreaTags(javax.swing.JTextArea txtAreaTags) {
        this.txtAreaTags = txtAreaTags;
    }

    public void update() {
        controllerSentence.fillComboBoxKorpus();
    }
}
